package com.example.websocket.threadTest;

public class InterruptTest extends Thread {

    public static void main(String[] args) {
        System.out.println("begin>>>>>>>>>>>>>>>>>");
        Thread interruptTest = new InterruptTest();
        interruptTest.start();
        try {
            sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("interrupt Thread>>>>>>>>>>>>>>>>>");
        interruptTest.interrupt();
        System.out.println("stop>>>>>>>>>>>>>>>>>>>");
    }

    @Override
    public void run() {
//        while (true) {
        while (!this.isInterrupted()) {
            System.out.println("Thread is running...");


            long time = System.currentTimeMillis();
            while (System.currentTimeMillis() - time < 1000) {

            }
        }
    }
}
